"
This is the unit test for the class Month.

"
Class {
	#name : 'MonthTest',
	#superclass : 'ClassTestCase',
	#instVars : [
		'month'
	],
	#category : 'System-Time-Tests',
	#package : 'System-Time-Tests'
}

{ #category : 'coverage' }
MonthTest >> classToBeTested [

	^ Month
]

{ #category : 'coverage' }
MonthTest >> selectorsToBeIgnored [

	| deprecated private special |
	deprecated := #().
	private := #( #printOn: ).
	special := #( #next ).

	^ super selectorsToBeIgnored, deprecated, private, special
]

{ #category : 'running' }
MonthTest >> setUp [

	super setUp.
	month := Month year: 1998 month: 7
]

{ #category : 'running' }
MonthTest >> tearDown [

	month := nil.
	super tearDown
]

{ #category : 'tests' }
MonthTest >> testConverting [
	self assert: month asDate equals: (Date readFrom: '1-7-1998' pattern: 'd-m-y')
]

{ #category : 'tests' }
MonthTest >> testEnumerating [
	| weeks |
	weeks := OrderedCollection new.
	month weeksDo: [ :w | weeks add: w start ].
	0 to: 4 do: [ :i | weeks remove: (Week starting: ((Date readFrom: '29-6-1998' pattern: 'd-m-y') addDays: i * 7)) start ].
	self assertEmpty: weeks
]

{ #category : 'tests' }
MonthTest >> testIndexOfMonth [
	| m |
	m := #(#January #February #March #April #May #June #July #August #September #October #November #December).

	m withIndexDo: [ :item :index | self assert: (Month indexOfMonth: item) equals: index ].

	self should: [ Month indexOfMonth: 1 ] raise: self defaultTestError.
	self should: [ Month indexOfMonth: #Marsh ] raise: self defaultTestError.
	"notice the misspell!!"
	self should: [ Month indexOfMonth: #UnexistingMonth ] raise: self defaultTestError
]

{ #category : 'tests' }
MonthTest >> testIndexOfMonthCaseInsensitive [
	self assert: (Month indexOfMonth: 'january') equals: 1.
	self assert: (Month indexOfMonth: #january) equals: 1.
	self assert: (Month indexOfMonth: 'jAnUaRy') equals: 1.
	self assert: (Month indexOfMonth: #jAnUaRy) equals: 1
]

{ #category : 'tests' }
MonthTest >> testIndexOfMonthIncompleteMonths [
	| m |
	m := #(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec).

	m withIndexDo: [ :item :index | self assert: (Month indexOfMonth: item) equals: index ]
]

{ #category : 'tests' }
MonthTest >> testIndexOfMonthWithStrings [
	| m |
	m := #(#January #February #March #April #May #June #July #August #September #October #November #December)
		collect: [ :aMonth | aMonth asString ].

	m withIndexDo: [ :item :index |
		self assert: (Month indexOfMonth: item) equals: index ]
]

{ #category : 'tests' }
MonthTest >> testInquiries [
	self
		assert: month index equals: 7;
		assert: month name equals: #July;
		assert: month duration equals: 31 days
]

{ #category : 'tests' }
MonthTest >> testInstanceCreation [
	| m1 m2 |
	m1 := Month starting: (Date readFrom: '4-7-1998' pattern: 'd-m-y').
	m2 := Month year: 1998 month: #July.
	self
		assert: month equals: m1;
		assert: month equals: m2
]

{ #category : 'tests' }
MonthTest >> testNameOfMonth [
	| m |
	m := #(#January #February #March #April #May #June #July #August #September #October #November #December).

	m withIndexDo: [ :item :index | self assert: (Month nameOfMonth: index) equals: item ].

	self should: [ Month nameOfMonth: 0 ] raise: self defaultTestError.
	self should: [ Month nameOfMonth: 13 ] raise: self defaultTestError.
	self should: [ Month nameOfMonth: #January ] raise: self defaultTestError
]

{ #category : 'tests' }
MonthTest >> testOffset [
	"Check that the offset is maintained when creating a new instance of Month from a DateAndTime"

	| dt newMonth |

	dt := DateAndTime fromString: '2018-01-01T00:00:00+10'.
	newMonth := Month starting: dt duration: 0. "duration is ignored"
	self assert: newMonth asDateAndTime offset equals: dt offset
]

{ #category : 'tests' }
MonthTest >> testPreviousNext [
	| n p |
	n := month next.
	p := month previous.

	self
		assert: n year equals: 1998;
		assert: n index equals: 8;
		assert: p year equals: 1998;
		assert: p index equals: 6
]

{ #category : 'tests' }
MonthTest >> testPrinting [
	self assert: month printString equals: 'July 1998'
]

{ #category : 'tests' }
MonthTest >> testReadFrom [
	| m |
	m := Month readFrom: 'July 1998' readStream.
	self assert: m equals: month
]
